| Conditions | 1 |
| Paths | 16 |
| Total Lines | 124 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 23 | app.factory('BoardService', function(ApiService, $http, $q){ |
||
| 24 | var BoardService = function($http, ep, $q) { |
||
| 25 | ApiService.call(this, $http, ep, $q); |
||
| 26 | }; |
||
| 27 | BoardService.prototype = angular.copy(ApiService.prototype); |
||
| 28 | |||
| 29 | BoardService.prototype.searchUsers = function(search) { |
||
| 30 | var url = OC.generateUrl('/apps/deck/share/search/'+search); |
||
|
|
|||
| 31 | var deferred = $q.defer(); |
||
| 32 | var self = this; |
||
| 33 | $http.get(url).then(function (response) { |
||
| 34 | |||
| 35 | self.sharees = []; |
||
| 36 | // filter out everyone who is already in the share list |
||
| 37 | angular.forEach(response.data, function(item) { |
||
| 38 | var exists = false; |
||
| 39 | angular.forEach(self.getCurrent().acl, function(acl) { |
||
| 40 | if (acl.participant === item.participant) { |
||
| 41 | exists = true; |
||
| 42 | } |
||
| 43 | }); |
||
| 44 | if(!exists) { |
||
| 45 | self.sharees.push(item); |
||
| 46 | } |
||
| 47 | }); |
||
| 48 | |||
| 49 | deferred.resolve(response.data); |
||
| 50 | }, function (error) { |
||
| 51 | deferred.reject('Error while update ' + self.endpoint); |
||
| 52 | }); |
||
| 53 | return deferred.promise; |
||
| 54 | }; |
||
| 55 | |||
| 56 | BoardService.prototype.addAcl = function(acl) { |
||
| 57 | var board = this.getCurrent(); |
||
| 58 | var deferred = $q.defer(); |
||
| 59 | var self = this; |
||
| 60 | var _acl = acl; |
||
| 61 | $http.post(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) { |
||
| 62 | if(!board.acl) { |
||
| 63 | board.acl = {}; |
||
| 64 | } |
||
| 65 | board.acl[response.data.id] = response.data; |
||
| 66 | deferred.resolve(response.data); |
||
| 67 | }, function (error) { |
||
| 68 | deferred.reject('Error creating ACL ' + _acl); |
||
| 69 | }); |
||
| 70 | acl = null; |
||
| 71 | return deferred.promise; |
||
| 72 | }; |
||
| 73 | |||
| 74 | BoardService.prototype.deleteAcl = function(acl) { |
||
| 75 | var board = this.getCurrent(); |
||
| 76 | var deferred = $q.defer(); |
||
| 77 | var self = this; |
||
| 78 | $http.delete(this.baseUrl + '/' + acl.boardId + '/acl/' + acl.id).then(function (response) { |
||
| 79 | delete board.acl[response.data.id]; |
||
| 80 | deferred.resolve(response.data); |
||
| 81 | }, function (error) { |
||
| 82 | deferred.reject('Error deleting ACL ' + acl.id); |
||
| 83 | }); |
||
| 84 | acl = null; |
||
| 85 | return deferred.promise; |
||
| 86 | }; |
||
| 87 | |||
| 88 | BoardService.prototype.updateAcl = function(acl) { |
||
| 89 | var board = this.getCurrent(); |
||
| 90 | var deferred = $q.defer(); |
||
| 91 | var self = this; |
||
| 92 | var _acl = acl; |
||
| 93 | $http.put(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) { |
||
| 94 | board.acl[_acl.id] = response.data; |
||
| 95 | deferred.resolve(response.data); |
||
| 96 | }, function (error) { |
||
| 97 | deferred.reject('Error updating ACL ' + _acl); |
||
| 98 | }); |
||
| 99 | acl = null; |
||
| 100 | return deferred.promise; |
||
| 101 | }; |
||
| 102 | |||
| 103 | BoardService.prototype.getPermissions = function() { |
||
| 104 | var board = this.getCurrent(); |
||
| 105 | var deferred = $q.defer(); |
||
| 106 | $http.get(this.baseUrl + '/' + board.id + '/permissions').then(function (response) { |
||
| 107 | board.permissions = response.data; |
||
| 108 | console.log(board.permissions); |
||
| 109 | deferred.resolve(response.data); |
||
| 110 | }, function (error) { |
||
| 111 | deferred.reject('Error fetching board permissions ' + board); |
||
| 112 | }); |
||
| 113 | }; |
||
| 114 | |||
| 115 | BoardService.prototype.canRead = function() { |
||
| 116 | if(!this.getCurrent() || !this.getCurrent().permissions) { |
||
| 117 | return false; |
||
| 118 | } |
||
| 119 | return this.getCurrent().permissions['PERMISSION_READ']; |
||
| 120 | } |
||
| 121 | |||
| 122 | BoardService.prototype.canEdit = function() { |
||
| 123 | if(!this.getCurrent() || !this.getCurrent().permissions) { |
||
| 124 | return false; |
||
| 125 | } |
||
| 126 | return this.getCurrent().permissions['PERMISSION_EDIT']; |
||
| 127 | } |
||
| 128 | |||
| 129 | BoardService.prototype.canManage = function() { |
||
| 130 | if(!this.getCurrent() || !this.getCurrent().permissions) { |
||
| 131 | return false; |
||
| 132 | } |
||
| 133 | return this.getCurrent().permissions['PERMISSION_MANAGE']; |
||
| 134 | } |
||
| 135 | |||
| 136 | BoardService.prototype.canShare = function() { |
||
| 137 | if(!this.getCurrent() || !this.getCurrent().permissions) { |
||
| 138 | return false; |
||
| 139 | } |
||
| 140 | return this.getCurrent().permissions['PERMISSION_SHARE']; |
||
| 141 | } |
||
| 142 | |||
| 143 | service = new BoardService($http, 'boards', $q); |
||
| 144 | return service; |
||
| 145 | |||
| 146 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.